#导入内置模块
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

msg = MIMEText("这是py测试邮件发送","html","utf-8")
msg["From"] = formataddr(["fengzh","dbcj2015@163.com"])
msg["To"] = "2294858562@qq.com"
msg["Subject"] = "这是测试邮件"

try:
    server = smtplib.SMTP_SSL("smtp.163.com",465)
    # 账号 + 授权码【网易云邮件中开启 POP3/SMTP服务 后会生成相关的授权码】
    server.login("dbcj2015@163.com","RDP5gkJBGdtJfxFN")
    server.sendmail("dbcj2015@163.com","2294858562@qq.com",msg.as_string())
    server.quit()
    print("发送成功")
except Exception as e:
    print(e)


